package com.yto.hrreport.event.buttons {
	import com.yto.hrreport.command.sysTemplatePanel;
	import com.yto.hrreport.event.buttons.superbutton.ButtonEvent;
	
	import mx.collections.ArrayCollection;
	import mx.containers.Canvas;
	import mx.containers.HDividedBox;
	import mx.controls.DataGrid;
	import mx.controls.Tree;
	
	public class TempEditButtonEvent extends ButtonEvent {
		
		private static var editEvent : TempEditButtonEvent = new TempEditButtonEvent();
		private static var parentName : String;
		private var oldHeadPosProvider : ArrayCollection;
		private var oldBodyPosProvider : ArrayCollection;
		
		public function TempEditButtonEvent() {
			super();
		}
		
		public static function getInstance(parentName : String) : TempEditButtonEvent {
			TempEditButtonEvent.parentName = parentName;
			return editEvent;
		}
		
		public function edit() : void {
			
			var parentCanvas : Canvas = Canvas(hrreport.ui.mainNavigator.getChildByName(parentName + "_canvas"));
			var headCanvas : Canvas = Canvas(parentCanvas.getChildByName(parentName + "_headCanvas"));
			var bodyCanvas : Canvas = Canvas(parentCanvas.getChildByName(parentName + "_bodyCanvas"));
			var hdivBox : HDividedBox = HDividedBox(bodyCanvas.getChildByName(parentName + "_hdivBox"));
			var sysTree : Tree = Tree(hdivBox.getChildByName(parentName + "_sysTree"));
			var template : sysTemplatePanel = sysTemplatePanel.getInstance();
			
			if(sysTree != null && sysTree.selectedItem != null) {
				
				sysTree.enabled = false;
				
				oldHeadPosProvider = new ArrayCollection();
				var headProvider : ArrayCollection = template.headPosGrid.dataProvider as ArrayCollection;
				for each(var item : Object in headProvider) {
					oldHeadPosProvider.addItem(item);
				}
				
				oldBodyPosProvider = new ArrayCollection();
				var bodyProvider : ArrayCollection = template.bodyPosGrid.dataProvider as ArrayCollection;
				for each(var item : Object in bodyProvider) {
					oldBodyPosProvider.addItem(item);
				}
				
				template.txtFieldCode.enabled = true;
				template.txtFieldName.enabled = true;
				template.combPos.enabled = true;
				template.btnAddRow.enabled = true;
				template.btnEditGrid.enabled = true;
				
				updateButtons(null , "sysEdit" , headCanvas , true);
				
			}
			
		}
		
		public function getOldHeadPosProvider() : ArrayCollection {
			return oldHeadPosProvider;
		}
		
		public function getOldBodyPosProvider() : ArrayCollection {
			return oldBodyPosProvider;
		}
		
	}
}